/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once
#include <cstddef>
#include <vector>

#include "highfive/H5File.hpp"

#include "DataStructure/Common/Id.h"
#include "DataStructure/Common/Integer.h"
#include "DataStructure/Common/Real.h"
#include "DataStructure/Result/ResultDomains.h"

#include "DBManager/Common/DBManagerNamespace.h"
#include "DBManager/Database/HDF5Database.h"
#include "DBManager/IRepository/Result/IResultDomainsRepository.h"
#include "DBManager/Repository/HDF5/Base/SingleRepositoryBase.h"

template <>
inline HighFive::DataType HighFive::create_datatype<SG::DataStructure::Post::ResultDomains> ()
{
    HighFive::CompoundType ct = {
        { "ID", HighFive::create_datatype<SG::DataStructure::Common::Id> () },
        { "SUBCASE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "STEP", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "ANALYSIS", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "TIME_FREQ_EIGR", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
        { "EIGI", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
        { "MODE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "DESIGN_CYCLE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "RANDOM", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "SE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "AFPM", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "TRMC", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "INSTANCE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "MODULE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "SUBSTEP", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "IMPFID", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
    };
    return ct;
}

SG_DBMANAGER_HDF5_NAMESPACE_OPEN
class ResultDomainsRepository : public IResultDomainsRepository, public SingleRepositoryBase<SG::DataStructure::Post::ResultDomains>
{
  public:
    explicit ResultDomainsRepository (HDF5Database& database);

    void InitialDatasetInfo () override;

    void UpdataMaxDomainId () override;

    std::vector<SG::DataStructure::Post::ResultDomains> GetAllData () override;
};
SG_DBMANAGER_HDF5_NAMESPACE_CLOSE
